package elion.com.theElion.fragmentSeed;

import android.os.AsyncTask;

import java.util.ArrayList;
import java.util.List;

import elion.com.theElion.utils.HttpUtils;
import elion.com.theElion.utils.JsonUtils;
import elion.vo.seed.Family;

/**
 * Created by Alex on 2017/7/15.
 * 此异步用来加载spinner中的科与属值
 */

public class FamilyAsy extends AsyncTask<String,Void,String> {
    /**
     * @param families 科或属列表
     */
    private List<Family> families = new ArrayList<>();

    private CallBack callBack;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected String doInBackground(String... params) {
        return HttpUtils.sendPostMethod(params[0],"utf-8");
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        System.out.println(s);
        if(s == null){
                families = null;
        }else {
            try {
                families = JsonUtils.jsonToList(new Family(), s);
                callBack.setList(families);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public void setCallback(CallBack callBack){
        this.callBack = callBack;
    }

    public interface CallBack {
        void setList(List<Family> list);
    }
}
